<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="mailCompose">
    <div class="callout callout-danger error_div" style="display:none;">
        <h4>Warning!</h4>

        <p class="error_msg"></p>
    </div>

    <div class="callout callout-info" id="draftSaved" style="display: none;">

        <p >当前编辑的邮件已保存到草稿箱</p>
    </div>
    <div class="box-header with-border">
        <h3 class="box-title">发送新消息</h3>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <input type="hidden" value="${draftId}" id="driftId"/>
        <div class="form-group">
            <input class="form-control" placeholder="To:" id="to"
                   value="${draft.to}">
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="CC:(可选)" id="cc" value="${draft.cc}">

        </div>
        <div class="form-group">
            <input class="form-control" placeholder="BCC:(可选)" id="bcc" value="${draft.bcc}">
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="Subject:" id="subject" value="${draft.subject}">
        </div>
        <div class="form-group">
            <textarea id="compose-textarea" class="form-control"
                      style="height: 300px">
                ${draft.content}
            </textarea>
        </div>
        <div class="form-group">
            <div class="btn btn-default btn-file">
                <i class="fa fa-paperclip"></i> Attachment <input type="file"
                                                                  name="attachment">
            </div>
            <p class="help-block">最大. 32MB</p>
        </div>

        <div class="form-group">
            <select id="email">
                <c:forEach items="${emails}" var="item">

                    <option value="${item.id}" <c:if test="${item.id.equals(draft.emailId)}">
                        selected = selected
                    </c:if> >
                        ${item.account}
                    </option>
                </c:forEach>

            </select>
        </div>
    </div>
    <div id="error_div" class="callout callout-danger"
         style="display: none">
        <h4>Warning!</h4>

        <p id="error_msg"></p>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        <div class="pull-right">
            <button id="saveBtn"  type="button" class="btn btn-default">
                <i class="fa fa-pencil"></i> 保存
            </button>
            <button id="send_btn" type="submit" class="btn btn-primary">
                <i class="fa fa-envelope-o"></i> 发送
            </button>
        </div>
        <button type="reset" class="btn btn-default">
            <i class="fa fa-times"></i> 删除
        </button>
    </div>
    <!-- /.box-footer -->
</div>
<script src="${pageContext.request.contextPath}/res/js/list.js"></script>
<script>
    $(function (){



        //加载富文本
        var editor = $("#compose-textarea").wysihtml5();
        //发送按钮点击事件
        $("#send_btn").click(function () {
            var to = $("#to").val();
            var cc = $("#cc").val();
            var bcc = $("#bcc").val();
            var subject = $("#subject").val();
            var html = $('#compose-textarea').val();
            alert(html);
            alert(to + "<br>" + cc + "<br>" + bcc + "<br>" + subject + "<br>" + html + "<br>");
            if (to == "") {
                $(".error_div").css("display", "block");
                $(".error_msg").text("请输入收件人");
            } else if (subject == "") {
                $(".error_div").css("display", "block");
                $(".error_msg").text("请输入主题");
            } else {
                $.post("/mailm/mail/compose.shtml", {
                    "to": to,
                    "copyTo": cc,
                    "bcc": bcc,
                    "subject": subject,
                    "body": html
                })
            }

        })
        $('#saveBtn').click(function (){
            saveDraft();
        })
    })

</script>